package com.example.mall.web.controller;

import com.example.mall.dto.SystemLogsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.service.ISystemLogsService;
import com.example.mall.domain.SystemLogs;
import com.example.mall.query.SystemLogsQuery;
import com.example.mall.result.JSONResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemLogs")
public class SystemLogsController {

    @Autowired
    public ISystemLogsService systemLogsService;

    /**
     * 分页查询系统日志表信息
     * @param systemLogsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询系统日志表信息",notes = "分页查询系统日志表信息",httpMethod = "GET")
    public JSONResult queryPage(SystemLogsQuery systemLogsQuery){
        PageDTO<SystemLogsDto> systemLogsDtoPageDTO = systemLogsService.queryPage(systemLogsQuery);
        return JSONResult.success("查询成功",systemLogsDtoPageDTO);
    }

    /**
     * 根据id查询系统日志表信息
     * @param logId
     * @return
     */
    @GetMapping("query/{logId}")
    @ApiOperation(value = "根据id查询系统日志表信息",notes = "根据id查询系统日志表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("logId")Long logId){
        //1.根据id查询用户信息
        if (logId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOGID_NOT_ID);
        }
        SystemLogs systemLogs = systemLogsService.getById(logId);
        return JSONResult.success("查询成功",systemLogs);
    }

    /**
     * 根据id查询系统日志表信息
     * @param logId
     * @return
     */
    @GetMapping("querySystemLogsById/{logId}")
    @ApiOperation(value = "根据id查询系统日志表信息",notes = "根据id查询系统日志表信息",httpMethod = "GET")
    public JSONResult querySystemLogsById(@PathVariable("logId")Long logId){
        //1.根据id查询用户信息
        if (logId == null){
            throw new GlobalCustomerException(ErrorEnumCode.LOGID_NOT_ID);
        }
        SystemLogs systemLogs = systemLogsService.querySystemLogsById(logId);
        return JSONResult.success("查询成功",systemLogs);
    }

    /**
     * 查询全部系统日志表信息
     * @param
     * @return
     */
    @GetMapping("querySystemLogsList")
    @ApiOperation(value = "查询全部系统日志表信息",notes = "查询全部系统日志表信息",httpMethod = "GET")
    public JSONResult querySystemLogsList(){
        List<SystemLogs> systemLogs = systemLogsService.querySystemLogsList();
        return JSONResult.success("查询成功",systemLogs);
    }

    /**
     * 新增系统日志表
     * @param systemLogsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增系统日志表",notes = "新增系统日志表",httpMethod = "POST")
    public JSONResult insert(@RequestBody SystemLogsDto systemLogsDto){
        systemLogsService.insert(systemLogsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改系统日志表信息
     * @param systemLogsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改系统日志表信息",notes = "修改系统日志表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody SystemLogsDto systemLogsDto){
        systemLogsService.update(systemLogsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除系统日志表信息
     * @param logId
     * @return
     */
    @PostMapping("delete/{logId}")
    @ApiOperation(value = "删除系统日志表信息",notes = "删除系统日志表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("logId") Long logId) {
        systemLogsService.delete(logId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除系统日志表信息
     * @param logIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除系统日志表信息",notes = "批量删除系统日志表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> logIds) {
        systemLogsService.deleteBatch(logIds);
        return JSONResult.success("批量删除成功");
    }
}
